package com.dtx.module.page;

import cn.hutool.core.collection.CollUtil;
import org.beetl.sql.core.page.PageResult;

import java.util.ArrayList;
import java.util.List;


public class BeePageResult<T> implements PageResult<T> {

    private long page;
    private int pageSize;
    private long totalRow;
    private List<T> list;
    private long totalPage;

    private int currentPage;
    private int totalCount;

    private String message;



    /**
     * 计算总共有多少页
     */
    protected void calcTotalPage() {
        if (totalRow == 0) {
            this.totalPage = 1;
            this.currentPage = 1;
        } else if (totalRow % this.pageSize == 0) {
            this.totalPage = totalRow / this.pageSize;
        } else {
            this.totalPage = totalRow / this.pageSize + 1;
        }
    }

    public static BeePageResult empty(){
        BeePageResult result = new BeePageResult();
        result.setList(CollUtil.empty(ArrayList.class));
        return result;
    }

    public BeePageResult() {
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public long getTotalRow() {
        return totalRow;
    }

    public void setTotalRow(long totalRow) {
        this.totalRow = totalRow;
    }

    @Override
    public List<T> getList() {
        return list;
    }

    @Override
    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(long totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
